package logic

import (
	"context"
	"inventory-system/api/internal/svc"
	"inventory-system/api/internal/types"
	"inventory-system/inventrpc/inventrpcclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductUploadLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductUploadLogic {
	return &ProductUploadLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductUploadLogic) ProductUpload(req *types.ProductUploadRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	upload, err := l.svcCtx.InventRpc.ProductUpload(l.ctx, &inventrpcclient.ProductUploadRequest{
		Title:     req.Title,
		UserId:    req.UserId,
		Price:     float32(req.Price),
		Stock:     req.Stock,
		Image:     req.Image,
		ProductId: req.ProductId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "修改成功",
		Data:    upload,
		Code:    200,
	}, nil

}
